//
//  CZEmoticonButton.swift
//  微博
//
//  Created by 霸气的刘吉庆 on 16/4/28.
//  Copyright © 2016年 ios. All rights reserved.
//

import UIKit

class CZEmoticonButton: UIButton {

    //自定义按钮,里面有一个属性,那就是什么呢,那就是emoticonModel
    var emoticonModel: CZEmoticonModel? {
        didSet{
            //如果里面是空值,直接return
            guard let model = emoticonModel else {
                return
            }
            //判断是否是emoji表情
            if model.type == "1" {
                //等于代表的是emoji表情
                let title = (model.code! as NSString).emoji()
                
                self.setTitle(title, forState: .Normal)
                //因为会复用,所以需要设置imageView的图片
                self.setImage(nil, forState: .Normal)
            }else{
                let image = UIImage(named: "\(model.folderName ?? "")/\(model.png ?? "")", inBundle: CZEmoticonKeyBoardViewModel.sharedViewModel.emoticonBundle, compatibleWithTraitCollection: nil)
                self.setImage(image, forState: .Normal)
                //设置title
                self.setTitle(nil, forState: .Normal)
                
                
                
            }
                
                
        }

}

}
